package com.qidian.buy.item.mq;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * Author: 戴着假发的程序员
 * Date: 2024-05-15 10:09
 * company: 起点编程
 * 消息接受者
 **/
//@Component
public class MessageReceive {

    // 准备一个方法来接收消息
    // 这个组件一旦被加载，这里就会产生一个监听者，监听simple-queue队列
    @RabbitListener(queues = {"simple-queue"})
    public void receiveMessageA(String message) {
        System.out.println("接收端[A]接收到的消息是：" + message);
        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    @RabbitListener(queues = {"simple-queue"})
    public void receiveMessageB(String message) {
        System.out.println("接收端[B]接收到的消息是：" + message);
        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    @RabbitListener(queues = {"simple-queue"})
    public void receiveMessageC(String message) {
        System.out.println("接收端[C]接收到的消息是：" + message);
        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
